package com.zhanpple.color_picker.library.circle

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.zhanpple.color_picker.library.databinding.CircleColorPickerBinding

/**
 * @author zmp
 * @date 2018/6/20
 */
class CircleColorPickerLayout @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
    private val mViewBinding by lazy {
        CircleColorPickerBinding.inflate(LayoutInflater.from(context), this)
    }

    init {
        mViewBinding.colorValuePicker.mColorValueBack = { value, _ ->
            mViewBinding.circleColorPicker.setColorValue(value)
        }
        mViewBinding.circleColorPicker.mColorBack = {
            mViewBinding.colorValuePicker.setCurrentColor(it, useValue = false, back = false)
            mViewBinding.colorProgress.setCurrentColor(it)
        }
        mViewBinding.colorProgress.mColorBack = {
            mViewBinding.colorShowPreView.mColor = it
        }
        //TODO test color
        resumeColor(Color.parseColor("#AAFF22FF"))
    }

    private fun resumeColor(parseColor: Int) {
        mViewBinding.colorValuePicker.setCurrentColor(parseColor, useValue = true, back = false)
        mViewBinding.circleColorPicker.setCurrentColor(parseColor, back = false)
        mViewBinding.colorProgress.setCurrentColor(parseColor, useAlpha = true, back = true)
    }
}